﻿$(function () {
    SelectAdvertisement();
    getSymbol();
});

function SelectAdvertisement() {
    $.ajax({
        url: "http://192.168.4.236:8081/ad/web/getAdList/APP_chefuwu_01",
        // data: { action: "SelectAdvertisement", showPosition: "APP_chefuwu_01", userType: "app" },
        cache: false,
        dataType: "json",
        success: function (res) {
            var html = "";
            if (res.code == "1000") {
                var data = res.data.advertisements[0]["advertisement"];
                for (var i = 0; i < data.length; i++) {
                    var imageUrl = replaceUrl(data[i]["adJson"]["imageUrl"]);
                    var img = replaceUrl(data[i]["adJson"]["imageAddress"]["img"]);
                    html += '<div class="swiper-slide">';
                    html += '<img src="' + data[i]["adJson"]["imageAddress"]["img"] + '">';
                    html += '</div>';
                    console.log(img);
                }

            }
            $(".banner").append(html);
            var mySwiper = new Swiper ('.swiper-container', {
                direction: 'horizontal',
                loop: true,
                autoplay: 5000,
                autoplayDisableOnInteraction: false
            })
        }
    });
}

//广告跳转地址
function AdvertRef(refUrl, umengName) {
    if (refUrl != "" && refUrl != "null") {
        window.cx580.jsApi.call({
            "commandId": "",
            "command": "openNewBrowserWithURL",
            "data": { "url": refUrl, "umengId": umengName }
        });
    }
}


var accountId = "";
var phone = "";
var version = "";
var userId = "";

//获取转义符数据
function getSymbol() {
    setTimeout(function () {
        window.cx580.jsApi.call({
            "commandId": "",
            "command": "getSymbol",
            "data": { "userid": "", "lng": "", "version": "", "channel": "", "cars": "", "phone": "", "name": "", "type|orderNum": "", "city": "", "accountId": "" }
        }, function (result) {
            accountId = result.data.accountId;
            phone = result.data.phone;
            version = result.data.version;
            userId = result.data.userid;
        });
    }, 500);
}

// //车险比价
// function carComparePrice() {
//     var gotoUrl = "http://mobile.cx580.com:9080/appmsg/FW?F=153"; //车险比价http://mobile.cx580.com:9080/appmsg/FW?F=112
//     if (accountId == "") {
//         accountId = userId;
//     }
//     window.cx580.jsApi.call({
//         "commandId": "",
//         "command": "openNewBrowserWithURL",
//         //"data": { "url": "http://mpay.cx580.com:8015/Page/YiInsurance/Auth.aspx?userid=" + accountId, "umengId": "cfw_chexianbijia" }
//         "data": { "url": gotoUrl, "umengId": "cfw_chexianbijia" }
//     });
// }

function commGoPage(url, umengName) {
    window.cx580.jsApi.call({
        "commandId": "",
        "command": "openNewBrowserWithURL",
        "data": { "url": url, "umengId": umengName }
    });
}
